package logic

import (
	"context"
	"fmt"
	"zhihu/mobels/mysql"
	"zhihu/zhihurpc/internal/svc"
	"zhihu/zhihurpc/zhihurpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PerfectUserLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPerfectUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PerfectUserLogic {
	return &PerfectUserLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PerfectUserLogic) PerfectUser(in *zhihurpc.PerfectUserRequest) (*zhihurpc.PerfectUserResponse, error) {
	// todo: add your logic here and delete this line
	var user mysql.User
	user = mysql.User{
		HeaderImage: in.HeaderImage,
		Sex:         in.Sex,
		Info:        in.Info,
		NickName:    in.NickName,
		Address:     in.Address,
		Career:      in.Career,
		Education:   in.Education,
	}
	err := mysql.DB.Debug().Updates(&user).Error
	if err != nil {
		return nil, fmt.Errorf("完善信息失败")
	}

	return &zhihurpc.PerfectUserResponse{UserId: int64(user.ID)}, nil
}
